package youkeda;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServer {
    public static void main(String[] args) throws IOException {

        ServerSocket serverSocket=new ServerSocket(8888);
        Socket accept = serverSocket.accept();
        System.out.println("服务端已经开启");
        //得到客户端传过来的信息
        InputStream inputStream = accept.getInputStream();
        byte[] bytes=new byte[1024];
        int length=inputStream.read(bytes);
        System.out.println(new String(bytes,0,length));
        //对客户端发送已经收到的信息内容
        OutputStream outputStream = accept.getOutputStream();
        outputStream.write("已经收到信息".getBytes());


        outputStream.close();
        inputStream.close();
        serverSocket.close();
    }
}
